<?php
/**
 * Created by PhpStorm.
 * User: lzy
 * Date: 2018/11/19
 * Time: 14:57
 */

namespace App\FreeBird\Controllers\Home;

use App\Base\Controllers\Controller;
use App\FreeBird\Contracts\CustomerServiceInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class CustomerServiceController extends Controller
{

    /**
     * 客服操作接口
     * @return CustomerServiceInterface
     */
    public function getCustomerServiceInterface()
    {
        return app()->make(CustomerServiceInterface::class);
    }


    /**
     * 获取客服发表列表
     * @param Request $request
     * @return mixed
     */
    public function getCsList(Request $request)
    {
        $where = function ($query) {
            $query->where("uid", AUID);
        };
        return $this->getCustomerServiceInterface()->getList($where);
    }

    /**
     * 添加客服回复
     * @return mixed
     */
    public function setCsList(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'content' => 'required'
        ]);
        if ($validator->fails()) {
            //$error=$validator->errors()->getMessages();
            $this->throwValidatorException($validator);
        }
        return $this->getCustomerServiceInterface()->addCustomerData($request->except("token"));
    }

}